package com.dewod.producesales.utils.request;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.ObjectUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.dewod.producesales.model.request.EnableOrderQuery;
import com.dewod.producesales.model.request.OrderDelivery;
import com.dewod.producesales.model.request.SnSubmit;
import com.dewod.producesales.model.request.SnValidate;
import com.dewod.producesales.model.response.base.ResponseData;
import com.dewod.producesales.utils.HttpUtil;
import com.google.firebase.crashlytics.buildtools.reloc.org.apache.http.message.BasicNameValuePair;

import org.json.JSONException;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * PDD 订单的请求工具类
 */
public class RequestApi4PddUtil extends RequestBaseUtil {


    public static void validateOrderNo(SnValidate form, CallBack<ResponseData> callBack) {
        new Thread(() -> {
            try {
                ApiEnums apiEnum = ApiEnums.PDD_VALIDATE_ORDER_NO;
                String responseData = doRequest(apiEnum, form);
                if (callBack != null) {
                    ResponseData ajax = JSON.parseObject(responseData,  ResponseData.class);
                    callBack.action(ajax);
                }
            } catch (Exception e) {
                Log.e("request", "请求订单号验证==================>" + e);
                ToastUtils.showLong(String.format("%s%s", "请求订单号验证==================>", e));
            }
        }).start();
    }

    public static void validateSn(SnValidate form, CallBack<ResponseData> callBack) {
        new Thread(() -> {
            try {
                ApiEnums apiEnum = ApiEnums.PDD_VALIDATE_ORDER_NO;
                String responseData = doRequest(apiEnum, form);
                if (callBack != null) {
                    ResponseData ajax = JSON.parseObject(responseData,  ResponseData.class);
                    callBack.action(ajax);
                }
            } catch (Exception e) {
                Log.e("request", "请求订单号验证==================>" + e);
                ToastUtils.showLong(String.format("%s%s", "请求订单号验证==================>", e));
            }
        }).start();
    }

    public static void formSubmit(SnSubmit form, CallBack<ResponseData> callBack) {
        new Thread(() -> {
            try {
                ApiEnums apiEnum = ApiEnums.PDD_SUBMIT_SN;
                String responseData = doRequest(apiEnum, form);
                if (callBack != null) {
                    ResponseData ajax = JSON.parseObject(responseData,  ResponseData.class);
                    callBack.action(ajax);
                }
//                Log.i("request", "请求订单号验证==================>" + responseData);
            } catch (Exception e) {
                Log.e("request", "请求订单号验证==================>" + e);
                ToastUtils.showLong(String.format("%s%s", "请求订单号验证==================>", e));
            }
        }).start();
    }

    public static void cancelOne(SnValidate form, CallBack<ResponseData> callBack) {
        new Thread(() -> {
            try {
                ApiEnums apiEnum = ApiEnums.PDD_CANCEL_ONE;
                String responseData = doRequest(apiEnum, form);
                if (callBack != null) {
                    ResponseData ajax = JSON.parseObject(responseData,  ResponseData.class);
                    callBack.action(ajax);
                }
            } catch (Exception e) {
                Log.e("request", "SN取消使用==================>" + e);
                ToastUtils.showLong(String.format("%s%s", "SN取消使用异常==================>", e));
            }
        }).start();
    }

    public static void cancel(SnSubmit form, CallBack<ResponseData> callBack) {
        new Thread(() -> {
            try {
                ApiEnums apiEnum = ApiEnums.PDD_CANCEL;
                String responseData = doRequest(apiEnum, form);
                if (callBack != null) {
                    ResponseData ajax = JSON.parseObject(responseData,  ResponseData.class);
                    callBack.action(ajax);
                }
            } catch (Exception e) {
                Log.e("request", "合同订单取消使用==================>" + e);
                ToastUtils.showLong(String.format("%s%s", "合同订单取消使用异常==================>", e));
            }
        }).start();
    }



}
